home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / chrome / dwhelper.jar / content / smart-name.xml < prev    next >
Extensible Markup Language  |  2010-01-15  |  15KB  |  542 lines

  1. <?xml version="1.0"?>
  2. <!-- *****************************************************************************
  3.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  4.  ****************************************************************************** -->
  5. <!DOCTYPE bindings SYSTEM "chrome://dwhelper/locale/dwhelper.dtd" >
  6.  
  7. <bindings xmlns="http://www.mozilla.org/xbl"
  8.     xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.     xmlns:html="http://www.w3.org/1999/xhtml"
  10.     xmlns:xbl="http://www.mozilla.org/xbl">
  11.  
  12.     <binding id="SmartNameLocation" extends="widgets.xml#widget">
  13.  
  14.         <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  15.             <vbox flex="1">
  16.                 <label value="&smartname.define.value-for-page;"/>
  17.                 <textbox anonid="xSample" readonly="true" style="-moz-appearance: none; background-color: #FFFFC0; padding: 5px; color: Black; border: 1px solid #808000; width: 400px; overlap: hidden;" flex="1" value="testXX"/>
  18.                 <groupbox>
  19.                     <caption>
  20.                         <checkbox label="Advanced" anonid="xAdvanced" oncommand="this.parentNode.parentNode.parentNode.parentNode.updateAdvanced()"/>
  21.                     </caption>
  22.                     <vbox flex="1" collapsed="true" anonid="xAdvPanel"> 
  23.                         <grid flex="1">
  24.                             <columns>
  25.                                 <column/>
  26.                                 <column flex="1"/>
  27.                             </columns>
  28.                             <rows>
  29.                                 <row align="center">
  30.                                     <label value="&smartname.define.domain;"/>
  31.                                     <vbox>
  32.                                         <label anonid="xSimpleDomain" hidden="true"/>
  33.                                         <radiogroup anonid="xMultiDomains" hidden="true" oncommand="this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.updateDomain()"/>
  34.                                     </vbox>
  35.                                 </row>
  36.                                 <row align="center">
  37.                                     <label value="&smartname.define.xpath;"/>
  38.                                     <textbox anonid="xXPath" oninput="this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.updateFromSelection()"/>
  39.                                 </row>
  40.                                 <row align="center">
  41.                                     <label value="&smartname.define.regexp;"/>
  42.                                     <textbox anonid="xRegExp" oninput="this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.updateFromSelection()"/>
  43.                                 </row>
  44.                             </rows>
  45.                         </grid>
  46.                         <groupbox collapsed="true" anonid="xPrev">
  47.                             <caption><text value="&smartname.define.previous-value;"/></caption>
  48.                             <grid flex="1" >
  49.                                 <columns>
  50.                                     <column/>
  51.                                     <column flex="1"/>
  52.                                 </columns>
  53.                                 <rows>
  54.                                     <row align="center">
  55.                                         <label value="&smartname.define.xpath;"/>
  56.                                         <textbox anonid="xPrevXPath" style="-moz-appearance: none; background-color: #C0C0C0;" readonly="true"/>
  57.                                     </row>
  58.                                     <row align="center">
  59.                                         <label value="&smartname.define.regexp;"/>
  60.                                         <textbox anonid="xPrevRegExp" style="-moz-appearance: none; background-color: #C0C0C0;" readonly="true"/>
  61.                                     </row>
  62.                                 </rows>
  63.                             </grid>
  64.                             
  65.                         </groupbox>
  66.                     </vbox>
  67.                 </groupbox>
  68.             </vbox>
  69.             <children style="display: none;"/>
  70.         </xbl:content>
  71.  
  72.         <implementation>
  73.  
  74.             <constructor>
  75.                 <![CDATA[
  76. this.smartNamer = Components.classes["@downloadhelper.net/smart-namer;1"]
  77.         .getService(Components.interfaces.dhISmartNamer);
  78. this.simpleDomain=true;
  79. this.NS="http://downloadhelper.net/1.0#";
  80.                 ]]>
  81.             </constructor>
  82.                         
  83.             <method name="setNode">
  84.                 <parameter name="node"/>
  85.                 <body>
  86.                 <![CDATA[
  87. this.document=node.ownerDocument;
  88.  
  89. var domain=/\/\/([^\/]+)\//.exec(node.ownerDocument.URL)[1];
  90. if(/^([^\.]*\.)?[^\.]*$/.test(domain)) { // simple domain
  91.     this.xSimpleDomain.value=domain;
  92.     this.xSimpleDomain.setAttribute("hidden","false");
  93.     this.domain=domain;
  94. } else {
  95.     var defDomain=null;
  96.     var parts=domain.split(".");
  97.     for(var i=0;i<parts.length-1;i++) {
  98.         var radio=document.createElement("radio");
  99.         var subdomain=parts.slice(i,parts.length).join(".");
  100.         radio.setAttribute("label",subdomain);
  101.         radio.setAttribute("value",subdomain);
  102.         radio.setAttribute("id",subdomain);
  103.         if(i==0)
  104.             radio.setAttribute("selected","true");
  105.         this.xMultiDomains.appendChild(radio);
  106.         if(defDomain==null)
  107.             defDomain=subdomain;
  108.     }
  109.     this.xMultiDomains.setAttribute("hidden","false");
  110.     this.simpleDomain=false;
  111.     this.domain=defDomain;
  112. }
  113.  
  114. var xpath=this.util.generateXPath(node);
  115. this.xXPath.value=xpath;
  116.  
  117. this.xRegExp.value=".*";
  118.  
  119. this.updatePrevious(this.domain,this.mode);    
  120.  
  121. this.updateFromSelection(node.ownerDocument);
  122.                 ]]>
  123.                 </body>
  124.             </method>
  125.  
  126.             <method name="setMode">
  127.                 <parameter name="mode"/>
  128.                 <body>
  129.                 <![CDATA[
  130. this.mode=mode;
  131.                 ]]>
  132.                 </body>
  133.             </method>
  134.             
  135.             <method name="updatePrevious">
  136.                 <parameter name="domain"/>
  137.                 <parameter name="mode"/>
  138.                 <body>
  139.                 <![CDATA[
  140. var rdfNode=this.smartNamer.getEntry(domain,mode);
  141. if(rdfNode) {
  142.     var ds=this.smartNamer.getDatasource();
  143.     this.xPrevXPath.value=Util.getPropertyValueRS(ds,rdfNode,this.NS+"xpath");
  144.     this.xPrevRegExp.value=Util.getPropertyValueRS(ds,rdfNode,this.NS+"regexp");
  145.     this.xPrev.collapsed=false;
  146. } else
  147.     this.xPrev.collapsed=true;
  148.                 ]]>
  149.                 </body>
  150.             </method>
  151.  
  152.             
  153.             <method name="updateAdvanced">
  154.                 <body>
  155.                 <![CDATA[
  156. this.xAdvPanel.setAttribute("collapsed",!this.xAdvanced.checked);
  157. window.sizeToContent();
  158.                 ]]>
  159.                 </body>
  160.             </method>
  161.  
  162.             <method name="updateFromSelection">
  163.                 <body>
  164.                 <![CDATA[
  165. var text;
  166. try {
  167.     text=this.util.xpGetString(this.document.documentElement,this.xXPath.value);
  168.     this.xXPath.style.color="Black";
  169. } catch(e) {
  170.     this.xSample.value="";
  171.     this.xXPath.style.color="Red";
  172.     return;
  173. }
  174. text=text.replace(/\s{1,}/g,' ');
  175. text=text.replace(/^\s+/,'');
  176. text=text.replace(/\s+$/,'');
  177. if(this.xRegExp.value.length>0) {
  178.     var m=null;
  179.     try {
  180.         m=new RegExp(this.xRegExp.value).exec(text);
  181.         this.xRegExp.style.color="Black";
  182.     } catch(e) {
  183.         this.xRegExp.style.color="Red";
  184.     }
  185.     if(m==null || m.length==0)
  186.         text="";
  187.     else if(m.length==1)
  188.         text=m[0];
  189.     else if(m.length>1)
  190.         text=m[1];
  191.     text=text.replace(/^\s+/,'');
  192.     text=text.replace(/\s+$/,'');
  193. }
  194. this.xSample.value=text;
  195.                 ]]>
  196.                 </body>
  197.             </method>
  198.  
  199.             <method name="updateDomain">
  200.                 <body>
  201.                 <![CDATA[
  202. this.domain=this.xMultiDomains.selectedItem.getAttribute("value");
  203. this.updatePrevious(this.domain,this.mode);
  204. window.sizeToContent();
  205.                 ]]>
  206.                 </body>
  207.             </method>
  208.  
  209.             <property name="value">  
  210.                 <setter>
  211.                 <![CDATA[
  212.  
  213.                 ]]> 
  214.                 </setter>
  215.                 <getter>
  216.                 <![CDATA[
  217. var value=Components.classes["@mozilla.org/properties;1"].
  218.     createInstance(Components.interfaces.nsIProperties);
  219.  
  220. this.util.setPropsString(value,"mode",this.mode);
  221. this.util.setPropsString(value,"xpath",this.xXPath.value);
  222. this.util.setPropsString(value,"regexp",this.xRegExp.value);
  223. if(this.simpleDomain)
  224.     this.util.setPropsString(value,"domain",this.xSimpleDomain.value);
  225. else
  226.     this.util.setPropsString(value,"domain",this.xMultiDomains.selectedItem.getAttribute("value"));
  227. return value;
  228.                 ]]> 
  229.                 </getter>
  230.             </property>
  231.  
  232.                         
  233.         </implementation>
  234.                 
  235.     </binding>
  236.  
  237.     <binding id="SmartNameListControl" extends="widgets.xml#widget">
  238.  
  239.         <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  240.             <vbox
  241.                 flex="1"
  242.                 anonid="xPanel">
  243.                 
  244.                 <hbox align="center">
  245.                     <label value="&smartname.list.label.type;"/>
  246.                     <menulist anonid="xType" oncommand="this.parentNode.parentNode.parentNode.typeChanged()">
  247.                         <menupopup>
  248.                             <menuitem label="&smartname.list.type.name;" value="name"/>
  249.                             <menuitem label="&smartname.list.type.descr;" value="descr"/>
  250.                         </menupopup>
  251.                     </menulist>
  252.                 </hbox>
  253.                 <tree 
  254.                     anonid="xTree"
  255.                     flex="1"
  256.                     enableColumnDrag="false" 
  257.                     hidecolumnpicker="true"
  258.                     flags="dont-build-content" 
  259.                     datasources="rdf:null" 
  260.                     ref="urn:root"
  261.                     onselect="this.parentNode.parentNode.updateSelection()"
  262.                     sortResource="http://downloadhelper.net/1.0#domain"
  263.                     sortDirection="ascending"
  264.                     style="min-height:40px;"
  265.                     >
  266.                     
  267.                     <treecols>
  268.                         <treecol 
  269.                             id="dwhelper-smartname-domain-col0"
  270.                             anonid="xCol0"
  271.                             primary="true"
  272.                             flex="1"
  273.                             label="&smartname.column.domain;"
  274.                             sort="?domain"
  275.                             />
  276.                     </treecols>
  277.     
  278.                     <template>
  279.                         <rule>
  280.                             <conditions>
  281.                                 <content uri="?root"/>
  282.                                 <member container="?root" child="?entry"/>
  283.                                 <triple
  284.                                     anonid="xModeTriple" 
  285.                                     subject="?entry"
  286.                                      predicate="http://downloadhelper.net/1.0#mode"
  287.                                      object="name"/>
  288.                                 <triple
  289.                                     subject="?entry"
  290.                                      predicate="http://downloadhelper.net/1.0#domain"
  291.                                      object="?domain"/>
  292.                             </conditions>
  293.                               <action>
  294.                                 <treechildren>
  295.                                     <treeitem
  296.                                         uri="?entry" open="true">
  297.                                         <treerow>
  298.                                             <treecell                
  299.                                                 label="?domain"
  300.                                                 />
  301.                                         </treerow>
  302.                                     </treeitem>
  303.                                 </treechildren>
  304.                             </action>
  305.                         </rule>
  306.                     </template>
  307.     
  308.                 </tree>
  309.                 <hbox>
  310.                     <button label="&smartname.list.button.delete;" anonid="xDelBut" oncommand="this.parentNode.parentNode.parentNode.remove();" collapsed="true"/>
  311.                     <button label="&smartname.list.button.edit;" anonid="xEditBut" oncommand="this.parentNode.parentNode.parentNode.edit();" collapsed="true"/>
  312.                     <spacer flex="1"/>
  313.                     <button label="&smartname.list.button.import;" oncommand="this.parentNode.parentNode.parentNode.import();"/>
  314.                 </hbox>
  315.             </vbox>
  316.     
  317.             <children style="display: none;"/>
  318.         </xbl:content>
  319.  
  320.         <implementation>
  321.  
  322.             <constructor>
  323.                 <![CDATA[
  324. this.core=Components.classes["@downloadhelper.net/core;1"].
  325.             getService(Components.interfaces.dhICore);
  326. this.smartNamer = Components.classes["@downloadhelper.net/smart-namer;1"]
  327.     .getService(Components.interfaces.dhISmartNamer);
  328. this.util.setDatasource(this.xTree,this.smartNamer.getDatasource());
  329.                 ]]>
  330.             </constructor>
  331.  
  332.             <destructor>
  333.                 <![CDATA[
  334.                 ]]>
  335.             </destructor>
  336.  
  337.             <method name="remove">
  338.                 <body>
  339.                 <![CDATA[
  340. var selectCount = this.xTree.view.selection.count;
  341. if(selectCount>0) {
  342.     var res=this.xTree.builderView.getResourceAtIndex(this.xTree.currentIndex);
  343.     if(res!=null) {
  344.         this.smartNamer.removeEntry(res);
  345.         this.core.updateSmartName();
  346.     }
  347. }
  348.                 ]]>
  349.                 </body>
  350.             </method>
  351.             
  352.             <method name="edit">
  353.                 <body>
  354.                 <![CDATA[
  355.                 ]]>
  356.                 </body>
  357.             </method>
  358.             
  359.             <method name="import">
  360.                 <body>
  361.                 <![CDATA[
  362. this.smartNamer.import();
  363.                 ]]>
  364.                 </body>
  365.             </method>
  366.             
  367.             <method name="typeChanged">
  368.                 <body>
  369.                 <![CDATA[
  370. this.xModeTriple.setAttribute("object",this.xType.value);
  371. this.xTree.builder.rebuild();
  372.                 ]]>
  373.                 </body>
  374.             </method>
  375.             
  376.             <method name="updateSelection">
  377.                 <body>
  378.                 <![CDATA[
  379. if(this.xTree.currentIndex<0) {
  380.     this.xDelBut.collapsed=true;
  381.     //this.xEditBut.collapsed=true;
  382. } else {
  383.     this.xDelBut.collapsed=false;
  384.     //this.xEditBut.collapsed=false;
  385. }
  386.                 ]]>
  387.                 </body>
  388.             </method>
  389.             
  390.         </implementation>
  391.         
  392.         <handlers>
  393.             
  394.             <!-- 
  395.             <handler event="DOMAttrModified">
  396.                 <![CDATA[
  397.                 ]]>
  398.             </handler>
  399.              -->
  400.     
  401.         </handlers>
  402.  
  403.     </binding>
  404.  
  405.     <binding id="SmartNameOverlap" extends="widgets.xml#widget">
  406.  
  407.         <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  408.             <vbox
  409.                 flex="1"
  410.                 anonid="xPanel">
  411.                 
  412.                 <description>&smartname.overlap.description;</description>
  413.                 
  414.                 <tree 
  415.                     anonid="xTree"
  416.                     flex="1"
  417.                     enableColumnDrag="true" 
  418.                     hidecolumnpicker="true"
  419.                     editable="true"
  420.                     style="height: 150px; width: 300px;" 
  421.                     >
  422.                     
  423.                     <treecols>
  424.                         <treecol 
  425.                             id="dwhelper-smartname-domain-col2"
  426.                             primary="false"
  427.                             flex="0"
  428.                             type="checkbox" 
  429.                             editable="true"
  430.                             />
  431.                         <splitter class="tree-splitter"/>
  432.                         <treecol 
  433.                             id="dwhelper-smartname-domain-col0"
  434.                             primary="true"
  435.                             flex="1"
  436.                             label="&smartname.column.domain;"
  437.                             />
  438.                         <splitter class="tree-splitter"/>
  439.                         <treecol 
  440.                             id="dwhelper-smartname-domain-col1"
  441.                             primary="false"
  442.                             flex="0"
  443.                             label="&smartname.column.mode;"
  444.                             />
  445.                     </treecols>
  446.     
  447.                     <treechildren anonid="xRows" flex="1"/>
  448.     
  449.                 </tree>
  450.                 <hbox align="center">
  451.                     <!-- 
  452.                     <button label="&smartname.overlap.button.selectall;" oncommand="this.parentNode.parentNode.parentNode.select(true);"/>
  453.                     <button label="&smartname.overlap.button.selectnone;" oncommand="this.parentNode.parentNode.parentNode.select(false);"/>
  454.                      -->
  455.                      <description value="&smartname.overlap.select;"/>
  456.                      <html:a onclick="this.parentNode.parentNode.parentNode.select(true);">&smartname.overlap.selectall;</html:a>
  457.                      <spacer style="width: 8px;"/>
  458.                      <html:a onclick="this.parentNode.parentNode.parentNode.select(false);">&smartname.overlap.selectnone;</html:a>
  459.                 </hbox>
  460.             </vbox>
  461.             <children style="display: none;"/>
  462.         </xbl:content>
  463.  
  464.         <implementation>
  465.  
  466.             <constructor>
  467.                 <![CDATA[
  468. this.smartNamer = Components.classes["@downloadhelper.net/smart-namer;1"]
  469.     .getService(Components.interfaces.dhISmartNamer);
  470. this.datasource=this.smartNamer.getDatasource();
  471. this.NS="http://downloadhelper.net/1.0#";
  472.                 ]]>
  473.             </constructor>
  474.  
  475.             <destructor>
  476.                 <![CDATA[
  477.                 ]]>
  478.             </destructor>
  479.  
  480.             <method name="select">
  481.                 <parameter name="all"/>
  482.                 <body>
  483.                 <![CDATA[
  484. for(var ti=this.xRows.firstChild;ti;ti=ti.nextSibling) {
  485.     var tc=ti.firstChild.firstChild;
  486.     tc.setAttribute("value",""+all);
  487. }
  488.                 ]]>
  489.                 </body>
  490.             </method>
  491.  
  492.             <property name="value">  
  493.                 <setter>
  494.                 <![CDATA[
  495. while(this.xRows.firstChild) {
  496.     this.xRows.removeChild(this.xRows.firstChild);
  497. }
  498. for(var i in val) {
  499.     var res=val[i].QueryInterface(Components.interfaces.nsIRDFResource);
  500.     var domain=this.util.getPropertyValueRS(this.datasource,res,this.NS+"domain");
  501.     var mode=this.util.getPropertyValueRS(this.datasource,res,this.NS+"mode");
  502.     var ti=document.createElement("treeitem");
  503.     this.xRows.appendChild(ti);
  504.     var tr=document.createElement("treerow");
  505.     ti.appendChild(tr);
  506.     var tc=document.createElement("treecell");
  507.     tc.setAttribute("value","false");
  508.     tc.setAttribute("entry-resource",res.Value);
  509.     tr.appendChild(tc);
  510.     tc=document.createElement("treecell");
  511.     tc.setAttribute("editable",false);
  512.     tc.setAttribute("label",domain);
  513.     tr.appendChild(tc);
  514.     tc=document.createElement("treecell");
  515.     tc.setAttribute("editable",false);
  516.     tc.setAttribute("label",this.util.getText("smartname.overlap."+mode));
  517.     tr.appendChild(tc);
  518. }
  519.                 ]]> 
  520.                 </setter>
  521.                 <getter>
  522.                 <![CDATA[
  523. var RDF=this.util.getRDF();
  524. var selected=[];
  525. for(var ti=this.xRows.firstChild;ti;ti=ti.nextSibling) {
  526.     var tc=ti.firstChild.firstChild;
  527.     if(tc.getAttribute("value")=="false") {
  528.         selected.push(RDF.GetResource(tc.getAttribute("entry-resource")));
  529.     }
  530. }
  531. return selected; 
  532.                 ]]> 
  533.                 </getter>
  534.             </property>
  535.             
  536.         </implementation>
  537.         
  538.     </binding>
  539.  
  540.  
  541. </bindings>
  542.